package com.test;

import java.util.List;

import org.hibernate.Session;

import com.group1.model.Lecturer;
import com.group1.model.Question;
import com.group1.model.Topic;
import com.group1.util.SessionFactoryUtil;

public class testQuestion {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
	//	createQuestion(session);
	//	updateQuestion(session);
	//	deleteQuestion(session);
		getQuestion(session);
		session.getTransaction().commit();
	}

	public static void getQuestion(Session session)
	{
		List<Question> question = Question.getAllQuestion(session);
		//List<Question> question = Question.getQuestionByTopic(1, session);
		//List<Question> question = Question.getQuestionOfLecturer("LectureID1", session);
		for (Question q : question) {
			System.out.println("ID: " + q.questionId + ", Lecturer: " + q.lecturer.lecturerId + 
					", Topic: " + q.topic.topicId);
		}
	}
	
	public static void createQuestion(Session session)
	{
		Question q = new Question();
		q.setTopic(Topic.getTopicByID(1, session));
		q.setLecturer(Lecturer.getLecturerById("LectureID1", session));
		q.setQuestionDesc("Question Descript1");
		q.setQuestionType("Hard");
		q.setQuestionLevel(2);
		session.save(q);
	}
	
	public static void updateQuestion(Session session)
	{
		Question q = Question.getQuestionByID(6, session);
		q.setQuestionDesc("New Description");
		session.saveOrUpdate(q);
	}
	
	public static void deleteQuestion(Session session)
	{
		session.delete(Question.getQuestionByID(6, session));
	}
	
}
